<style>
  html,
  body {
    background-color: #f6f8fa;
  }
</style>
<div id="app" v-cloak>
  <div class="flex items-center p2">
    <div style="flex: 1">
      <a href="/client/home" class="weui-btn weui-btn_mini weui-btn_default"> 返回 </a>
    </div>
    <!-- <a href="/client/page/messages" class="weui-btn weui-btn_mini weui-btn_default">素材管理</a> -->
  </div>

  <div class="weui-form-preview mb2" v-for="send in sends">
    <div class="weui-form-preview__hd">
      <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">群发任务</label>
        <div class="weui-form-preview__value">{{send.name}}</div>
      </div>
    </div>
    <div class="weui-form-preview__bd">
      <div class="weui-form-preview__item">
        <div class="weui-form-preview__label">发送群聊:</div>
        <span>
          <span v-for="topic in send.topics"> {{topic}} </span>
        </span>
      </div>

      <div class="weui-form-preview__item">
        <div class="weui-form-preview__label">发送模式:</div>
        <span> {{send.mode==2?'定期发送': '手动发送'}} </span>
      </div>

      <div class="weui-form-preview__item" v-if="send.mode==2 && send.month!=1">
        <div class="weui-form-preview__label">发送周期:</div>
        <span>
          <span v-if="send.weekdays[1]">周一</span>
          <span v-if="send.weekdays[2]">周二</span>
          <span v-if="send.weekdays[3]">周三</span>
          <span v-if="send.weekdays[4]">周四</span>
          <span v-if="send.weekdays[5]">周五</span>
          <span v-if="send.weekdays[6]">周六</span>
          <span v-if="send.weekdays[0]">周日</span></span
        >
      </div>

      <div class="weui-form-preview__item" v-if="send.mode==2 && send.month==1">
        <div class="weui-form-preview__label">发送周期:</div>
        <span>每月{{send.days}}号</span>
      </div>

      <div class="weui-form-preview__item" v-if="send.mode==2">
        <div class="weui-form-preview__label">发送时间:</div>
        <span>{{send.daytime}} </span>
      </div>
    </div>

    <div class="weui-form-preview__ft">
      <div @click="doSend(send._id)" class="weui-form-preview__btn weui-form-preview__btn_primary">手动发送</div>
      <a v-bind:href="'/client/page/sendform/'+send._id" class="weui-form-preview__btn weui-form-preview__btn_primary"
        >编辑任务</a
      >
    </div>
  </div>
  <div class="p1 my2">
    <a href="/client/page/sendform" class="weui-btn weui-btn_primary">创建群发任务</a>
  </div>
  <div v-if="sends.length==0" class="gray py2 center">
    <img src="/img/empty.png" style="width: 150px" />
    <div class="font-12 bold">没有更多数据了</div>
  </div>
</div>

<script>
  new Vue({
    el: "#app",
    data: function () {
      return {
        sends: <%-JSON.stringify(sends)%>
      };
    },
    methods: {
      doSend: function(sendid){
        if(confirm('确定手动发送消息?')){
          axios.post('/client/send/'+sendid+'/dosend').then(function(){
            weui.alert('发送成功')
          })
        }
      }
    },
  });
</script>
